package com.lagou.goods.service.impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lagou.common.pojo.Goods;
import com.lagou.goods.Mapper.GoodsMapper;
import com.lagou.goods.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    private GoodsMapper goodsMapper;
    /**
     *  通过id查询商品
     * @param goodsId
     * @return
     */
    @Override
    public Goods findById(Integer goodsId) {
        return goodsMapper.selectById(goodsId);
    }

    /**
     * 通过id删除商品
     * @param goodsId
     * @return
     */
    @Override
    public int deleteById(Integer goodsId) {
        return goodsMapper.deleteById(goodsId);
    }

    /**
     *  通过id编辑商品
     * @param goods
     * @return
     */
    @Override
    public int updateById(Goods goods) {
        return goodsMapper.updateById(goods);
    }
    /**
     *  分页查询
     * @param yeshu
     * @return
     */
    @Override
    public  IPage<Goods> selectPage(Integer yeshu) {
        IPage<Goods> iPage = goodsMapper.selectPage(new Page<>(yeshu,10),null);
//        System.out.println("数据总条数：" + iPage.getTotal());
//        System.out.println("总⻚数：" + iPage.getPages());
//        List<Goods> goodsList = iPage.getRecords();
//        for (Goods goods : goodsList) {
//            System.out.println("user = " + goods);
//        }
        return  iPage;
    }


}
